window.onload=function(){
		var pbId = sessionStorage.getItem("pbId");
		
		var userId = sessionStorage.getItem("userId");
		console.log(pbId);
		 $.ajax({
		    type:"POST",
		    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/coverpaper",
		    data:{pbId:pbId,userId:userId},
		    dataType:"json",
		       beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(data=>{
				  	console.log(data);
					
		    		   var style=(data.style);	    		
		        		$("head").append("<link>");
   						 css = $("head").children(":last");
   						   css.attr({
					        rel: "stylesheet",
					        type: "text/css",
					        href:"http://www.youyiku-yishu.cn/Apps/WebApp/View/default/css/photoNewBook/coverpaper"+style+".css"
					    });
					    
					    $.getScript("../js/photoNewBook/parentOffspring"+style+".js",function(){
							});


				var pbook=data.pbook;
             	var photoCover=data.photoCover;
            
             	// var pbook=data.pbook;
           		var pbcover="";
            
             pbcover+='<div class="main">';
             pbcover+='<div class="main_cover">';
             pbcover+='<div class="cover">';
             pbcover+='<div class="coverTop">';
             pbcover+='<div class="coverNav">选择封面对封面对编辑将会实时生效哦</div>';
             pbcover+='<div class="bookName">';
             pbcover+='<span class="book_name left">作品书名</span>';
             pbcover+='<input type="text" name="" class="inputName right" placeholder="请输入作品书名" value="'+pbook.bookName+'" id="bookName" maxlength="9">';
             pbcover+='</div>';
             pbcover+='<div class="biaoName">';
             pbcover+='<span class="biao_name left">作者</span>';
             pbcover+='<input type="text" name="" class="inputbiao right" placeholder="请输入副标题或者作者名字" value="'+pbook.title+'" id="title" maxlength="8">';
             pbcover+='</div>';

             pbcover+='</div>';
             pbcover+='<div class="coverBot">';
             pbcover+='<div class="coverImg">';
             pbcover+='<div class="xuanze">选择封面</div>';
             pbcover+='<div class="coverStyle">';
             for(var i=0;i<photoCover.length;i++){
             	if(photoCover[i].pbId>0){
             		
             	}else{
             	 pbcover+='<div class="cover_style left left_'+i+'" onclick="cover('+i+','+photoCover[i].id+')">';
                 pbcover+='<div class="cover_style_img">';
//               pbcover+='<span class="uploadImg" style="z-index:5" onclick="uploadimg1('+i+')">可上传图片</span>';
                 pbcover+='<img src="http://www.youyiku-yishu.cn/'+photoCover[i].image+'" class="img">';
              	 if(photoCover[i].cId==photoCover[0].id){
              	 	pbcover+='<div  class="imgbox imgbox1">';
              	  for(var j=0;j<photoCover.length;j++){
              	  	if(photoCover[j].pbId>0 && photoCover[j].cId==photoCover[0].id){
              	  		pbcover+='<img  src="http://www.youyiku-yishu.cn/'+photoCover[j].image+'">';
              	  	}
              	 }
              	 	pbcover+='</div>';
              	 }else if(photoCover[i].cId==photoCover[1].id){
              	 	pbcover+='<div  class="imgbox imgbox2">';
              	 	 for(var j=0;j<photoCover.length;j++){
              	  	if(photoCover[j].pbId>0 && photoCover[j].cId==photoCover[1].id){
              	  		pbcover+='<img  src="http://www.youyiku-yishu.cn/'+photoCover[j].image+'">';
              	  	}
              	 }
              	 	pbcover+='</div>';
              	 }else if(photoCover[i].cId==photoCover[2].id){
              	 	pbcover+='<div  class="imgbox imgbox3">';
              	 	 for(var j=0;j<photoCover.length;j++){
              	  	if(photoCover[j].pbId>0 && photoCover[j].cId==photoCover[2].id){
              	  		pbcover+='<img  src="http://www.youyiku-yishu.cn/'+photoCover[j].image+'">';
              	  	}
              	 }
              	 	
              	 	pbcover+='</div>';
              	 }
                 pbcover+='</div>';
						if(pbook.coverId==photoCover[i].id){
                            pbcover+=' <div class="cover_style_top" data="'+photoCover[i].id+'">';
                        }else{
                            pbcover+='<div class="cover_style_top" data="'+photoCover[i].id+'">';
                        }


						if(pbook.coverId==photoCover[i].id){
                            pbcover+='<div class="coverTure cover_cur coverTure'+i+'" data="'+photoCover[i].id+'"><img src="http://www.youyiku-yishu.cn/Apps/WebApp/View/default/images/photo_book_edit_the_cover_selected_cover_icon_sel.png" class="img"></div>';
                        }else{
                            pbcover+='<div class="coverTure coverTure'+i+'" data="'+photoCover[i].id+'"><img src="http://www.youyiku-yishu.cn/Apps/WebApp/View/default/images/photo_book_edit_the_cover_selected_cover_icon_sel.png" class="img"></div>';
                        }


                 pbcover+='</div>';
                 pbcover+='</div>';
             	}
         

                 }



             pbcover+='</div>';

             for(var i=0;i<photoCover.length;i++){
				if(photoCover[i].cId==photoCover[0].cId){
                     if(photoCover[i].pbId==pbId){
                         pbcover+='<input type="hidden" value="'+photoCover[i].image+'" id="imagebox1">';
                         pbcover+='<input type="hidden" value="'+photoCover[i].shape+'" id="imageboxShape1">';
                     }
                 }else if(photoCover[i].cId===photoCover[1].cId){
                    if(photoCover[i].pbId==pbId){
                        pbcover+='<input type="hidden" value="'+photoCover[i].image+'" id="imagebox1">';
                        pbcover+='<input type="hidden" value="'+photoCover[i].shape+'" id="imageboxShape1">';
                    }
                }
				else if(photoCover[i].cId===photoCover[2].cId){
                    if(photoCover[i].pbId==pbId){
                        pbcover+='<input type="hidden" value="'+photoCover[i].image+'" id="imagebox1">';
                        pbcover+='<input type="hidden" value="'+photoCover[i].shape+'" id="imageboxShape1">';
                    }
                }
			 }

             pbcover+='</div>';
             pbcover+='</div>';
             pbcover+='</div>';
             pbcover+='</div>';
             pbcover+='</div>';
             pbcover+='<input type="hidden" id="coverId" value="'+pbook.coverId+'">';
			 pbcover+='<input type="hidden" name="" id="nun" value="" />';
			 pbcover+='<input type="hidden" name="" id="cId" value="'+pbook.coverId+'" />';
             pbcover+='<foot>';
             pbcover+='<div class="Foot">';
             pbcover+='<div class="Editcontent" id="Editcontent" onclick="bluepencil()">编辑内容</div>';
             pbcover+='<div class="thread-boundbook boundbook" id="thread_boundbook">编辑封面</div>';
             pbcover+='<div class="accomplish" id="accomplish" onclick="preview()">预览书本</div>';
             pbcover+='</div>';
             pbcover+='</foot>';
             $('.container').html(pbcover);
			 var length1= $('.imgbox1>img').length
			 if(length1!=0){
			 	$('.imgbox1').css('background-color','#FFFFFF');
			 }
			 var length2= $('.imgbox2>img').length
			 if(length2!=0){
			 	$('.imgbox2').css('background-color','#FFFFFF');
			 }
			 var length3= $('.imgbox3>img').length
			 if(length3!=0){
			 	$('.imgbox3').css('background-color','#FFFFFF');
			 }
		    });

}
//选择封面
function cover(num,ver){
	var ver=ver;
	var num=num;
	if(num==0){
		$('.coverTure2').removeClass('cover_cur');
		$('.coverTure1').removeClass('cover_cur');		
		$('.coverTure0').addClass('cover_cur');
	}else if(num==1){
		$('.coverTure0').removeClass('cover_cur');
		$('.coverTure2').removeClass('cover_cur');		
		$('.coverTure1').addClass('cover_cur');
	}else if(num==2){
		$('.coverTure0').removeClass('cover_cur');
		$('.coverTure1').removeClass('cover_cur');		
		$('.coverTure2').addClass('cover_cur');
	}
	$('#cId').val(ver);
}

//跳回编辑页面
function bluepencil(){
	var pbId = sessionStorage.getItem("pbId");
	var cId=$('#cId').val();	
	var bookName=$('#bookName').val();
	var title=$('#title').val();
	$.ajax({
		    type:"POST",
		    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/saveTitlePage",
		    data:{pbId:pbId,cId:cId,bookName:bookName,title:title},
		    dataType:"json",
		       beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(data=>{
		  	    var status=data.status;
		  	    	location.href = 'templet.html';	  	   
		  })
}
//去预览书
function preview(){
		var pbId = sessionStorage.getItem("pbId");
		var cId=$('#cId').val();	
		var bookName=$('#bookName').val();
		var title=$('#title').val();
		$.ajax({
			    type:"POST",
			    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/saveTitlePage",
			    data:{pbId:pbId,cId:cId,bookName:bookName,title:title},
			    dataType:"json",
			       beforeSend: function (XMLHttpRequest) {
			         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
			       }
			  }).then(data=>{
			  	    var status=data.status;
			  	    	location.href = 'preview.html';	  	   
			  })
}
$('#Editcontent').click(function(){
    var pbId=$('#pbId').val();
    var cid=$('.cover_cur').attr('data');
    var BookNane=$('.inputName').val();
    var inputbiao=$('.inputbiao').val();
    $.post(WST.U('WebApp/PhotoBooks/saveTitlePage'),{pbId:pbId,cId:cid,bookName:BookNane,title:inputbiao},function(json){
        if(json.status==1){

        }
        location.href = WST.U("WebApp/PhotoBooks/page",'pbId='+pbId);
    })

	
	
})
/*
 *
 */

